﻿using System.Collections.Generic;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;

namespace AutoCAD_CSharp_plug_in3.Chap02
{
    public static class IG54180LA1
    {
        // 541 80L 横向 单排
        public static List<Entity> HorizontalDP(Point3d startPoint, int num)
        {
            List<Entity> entities = new List<Entity>();
            //----------------------------------------横线-----------------------------------------------------
            //ws1 外上1
            Line ws1 = new Line(startPoint, new Point3d(startPoint.X + (150 + (320 * num)), startPoint.Y, 0));
            //ns1 内上1
            Line ns1 = new Line(startPoint.CP(50, -50), ws1.EndPoint.CP(-50, -50));
            //管道 集流管
            Line jlg = new Line(startPoint.CP(0, -150), ws1.EndPoint.CP(0, -150));
            //nx2 内下2
            Line nx2 = new Line(ns1.StartPoint.CP(0, -300), ns1.EndPoint.CP(0, -300));
            //wx2 外下2
            Line wx2 = new Line(ws1.StartPoint.CP(0, -400), ws1.EndPoint.CP(0, -400));
            //
            //
            //----------------------------------------竖线-----------------------------------------------------
            //s1 参照起点
            Line s1 = new Line(startPoint, startPoint.CP(0, -400));
            //s2 参照s1
            Line s2 = new Line(s1.StartPoint.CP(50, 0), s1.EndPoint.CP(50, 0));
            //s3 参照 ws1 末点   
            Line s3 = new Line(ws1.EndPoint.CP(-50, 0), ws1.EndPoint.CP(-50, -400));
            //s4 参照ws1 末点
            Line s4 = new Line(ws1.EndPoint, ws1.EndPoint.CP(0, -400));
            //ks1 参照ws1
            Line ks1 = new Line(startPoint.CP(25, -120), startPoint.CP(25, -180));
            //ks2 参照ks2  开孔2
            Line ks2 = new Line(ks1.StartPoint.CP((320 * num) + 100, 0), ks1.EndPoint.CP((320 * num) + 100, 0));

            //创建钢瓶圈
            double br = 248 / 2.0;
            double sr = 163 / 2.0;

            Circle cw1 = new Circle(startPoint.CP(235, -200), Vector3d.ZAxis, br);
            Circle cn1 = new Circle(cw1.Center, Vector3d.ZAxis, sr);
            entities.Add(cw1);
            entities.Add(cn1);

            if (num > 1)
            {
                for (int i = 1; i < num; i++)
                {
                    Circle cw = new Circle(cw1.Center.CP(320 * i, 0), Vector3d.ZAxis, br);
                    Circle cws = new Circle(cw1.Center.CP(320 * i, 0), Vector3d.ZAxis, sr);
                    entities.Add(cw);
                    entities.Add(cws);
                }
            }

            entities.Add(ws1);
            entities.Add(ns1);
            entities.Add(jlg);
            entities.Add(nx2);
            entities.Add(wx2);
            entities.Add(s1);
            entities.Add(s2);
            entities.Add(s3);
            entities.Add(s4);
            entities.Add(ks1);
            entities.Add(ks2);
            return entities;
        }


        //541 80L 竖向 单排
        public static List<Entity> VerticalDP(Point3d startPoint, int num)
        {
            List<Entity> entities = new List<Entity>();
            //----------------------------------------横线-----------------------------------------------------
            //ws1 外上1
            Line ws1 = new Line(startPoint, startPoint.CP(400, 0));
            //ns1 内上1
            Line ns1 = new Line(startPoint.CP(0, -50), ws1.EndPoint.CP(0, -50));

            //wx2 外下2
            Line wx2 = new Line(startPoint.CP(0, -(150 + (320 * num))), ws1.EndPoint.CP(0, -(150 + (320 * num))));
            //nx2 内下2
            Line nx2 = new Line(wx2.StartPoint.CP(0, 50), wx2.EndPoint.CP(0, 50));

            ////
            ////
            ////----------------------------------------竖线-----------------------------------------------------
            //s1 参照起点
            Line s1 = new Line(startPoint, wx2.StartPoint);
            //s2 参照s1
            Line s2 = new Line(s1.StartPoint.CP(50, -50), s1.EndPoint.CP(50, 50));
            //s3 参照 ws1 末点   
            Line s3 = new Line(s2.StartPoint.CP(300, 0), s2.EndPoint.CP(300, 0));
            //s4 参照ws1 末点
            Line s4 = new Line(s1.StartPoint.CP(400, 0), s1.EndPoint.CP(400, 0));

            ////管道 集流管
            Line jlg = new Line(s4.StartPoint.CP(-150, 0), s4.EndPoint.CP(-150, 0));

            //ks1 参照ws1
            Line ks1 = new Line(startPoint.CP(220, -25), startPoint.CP(280, -25));
            //ks2 参照ks2  开孔2
            Line ks2 = new Line(ks1.StartPoint.CP(0, -((320 * num) + 100)), ks1.EndPoint.CP(0, -((320 * num) + 100)));


            ////创建钢瓶圈
            double br = 248 / 2.0;
            double sr = 163 / 2.0;

            Circle cw1 = new Circle(startPoint.CP(200, -235), Vector3d.ZAxis, br);
            Circle cn1 = new Circle(cw1.Center, Vector3d.ZAxis, sr);
            entities.Add(cw1);
            entities.Add(cn1);

            if (num > 1)
            {
                for (int i = 1; i < num; i++)
                {
                    Circle cw = new Circle(cw1.Center.CP(0, -320 * i), Vector3d.ZAxis, br);
                    Circle cws = new Circle(cw1.Center.CP(0, -320 * i), Vector3d.ZAxis, sr);
                    entities.Add(cw);
                    entities.Add(cws);
                }
            }

            entities.Add(ws1);
            entities.Add(ns1);

            entities.Add(nx2);
            entities.Add(wx2);
            entities.Add(jlg);
            entities.Add(s1);
            entities.Add(s2);
            entities.Add(s3);
            entities.Add(s4);
            entities.Add(ks1);
            entities.Add(ks2);
            return entities;
        }


        // 541 80L 横向 双排
        public static List<Entity> HorizontalSP(Point3d startPoint, int sub_num)
        {
            int num = sub_num / 2;
            int num1 = sub_num % 2;
            if (num1 > 0) num++;

            List<Entity> entities = new List<Entity>();
            //----------------------------------------横线-----------------------------------------------------
            //ws1 外上1
            Line ws1 = new Line(startPoint, new Point3d(startPoint.X + (150 + (320 * num)), startPoint.Y, 0));
            //ns1 内上1
            Line ns1 = new Line(startPoint.CP(50, -50), ws1.EndPoint.CP(-50, -50));
            // z1
            //管道 集流管
            Line jlg = new Line(startPoint.CP(0, -325), ws1.EndPoint.CP(0, -325));
            //z2
            //nx2 内下2
            Line nx2 = new Line(ns1.StartPoint.CP(0, -550), ns1.EndPoint.CP(0, -550));
            //wx2 外下2
            Line wx2 = new Line(startPoint.CP(0, -650), ws1.EndPoint.CP(0, -650));
            //
            //
            //----------------------------------------竖线-----------------------------------------------------
            //s1 参照起点
            Line s1 = new Line(startPoint, wx2.StartPoint);
            Line s2 = new Line(s1.StartPoint.CP(50, 0), s1.EndPoint.CP(50, 0));
            //s3
            Line s3 = new Line(ws1.EndPoint, wx2.EndPoint);
            Line s4 = new Line(s3.StartPoint.CP(-50, 0), s3.EndPoint.CP(-50, 0));

            //ks1 参照ws1
            Line ks1 = new Line(startPoint.CP(25, -295), startPoint.CP(25, -355));
            //ks2 参照ks2  开孔2
            Line ks2 = new Line(ws1.EndPoint.CP(-25, -295), ws1.EndPoint.CP(-25, -355));


            //创建钢瓶圈
            double br = 248 / 2.0;
            double sr = 163 / 2.0;

            Circle cw1 = new Circle(startPoint.CP(235, -187.5), Vector3d.ZAxis, br);
            Circle cn1 = new Circle(cw1.Center, Vector3d.ZAxis, sr);
            entities.Add(cw1);
            entities.Add(cn1);

            Circle cw2_1 = null;
            if (sub_num > 1)
            {
                 cw2_1 = new Circle(startPoint.CP(235, -462.5), Vector3d.ZAxis, br);
                Circle cn2_1 = new Circle(cw2_1.Center, Vector3d.ZAxis, sr);
                entities.Add(cw2_1);
                entities.Add(cn2_1);
            }

            if (num > 1)
            {
                for (int i = 1; i < num; i++)
                {
                    Circle cw = new Circle(cw1.Center.CP(320 * i, 0), Vector3d.ZAxis, br);
                    Circle cws = new Circle(cw1.Center.CP(320 * i, 0), Vector3d.ZAxis, sr);
                    entities.Add(cw);
                    entities.Add(cws);
                    if (i < num)
                    {
                        if (num1 > 0 && i == num - 1) break;
                        if (sub_num>1)
                        {
                            if (cw2_1 != null)
                            {
                                Circle cw2 = new Circle(cw2_1.Center.CP(320 * i, 0), Vector3d.ZAxis, br);
                                Circle cws2 = new Circle(cw2_1.Center.CP(320 * i, 0), Vector3d.ZAxis, sr);
                                entities.Add(cw2);
                                entities.Add(cws2);
                            }
                        }
                    }
                }
            }

            entities.Add(ws1);
            entities.Add(ns1);
            entities.Add(jlg);
            entities.Add(nx2);
            entities.Add(wx2);
            entities.Add(s1);
            entities.Add(s2);
            entities.Add(s3);
            entities.Add(s4);
            entities.Add(ks1);
            entities.Add(ks2);
            return entities;
        }

        // 541 80L 竖向 双排
        public static List<Entity> VerticalSP(Point3d startPoint, int sub_num)
        {
            int num = sub_num / 2;
            int num1 = sub_num % 2;
            if (num1 > 0) num++;

            List<Entity> entities = new List<Entity>();
            //----------------------------------------横线-----------------------------------------------------
            //ws1 外上1
            Line ws1 = new Line(startPoint, new Point3d(startPoint.X, startPoint.Y - (150 + (320 * num)), 0));
            //ns1 内上1
            Line ns1 = new Line(startPoint.CP(50, -50), ws1.EndPoint.CP(50, 50));
            // z1
            //管道 集流管
            Line jlg = new Line(startPoint.CP(325, 0), ws1.EndPoint.CP(325, 0));
            //z2
            //nx2 内下2
            Line nx2 = new Line(ns1.StartPoint.CP(550, 0), ns1.EndPoint.CP(550, 0));
            //wx2 外下2
            Line wx2 = new Line(startPoint.CP(650, 0), ws1.EndPoint.CP(650, 0));
            //
            //
            //----------------------------------------竖线-----------------------------------------------------
            //s1 参照起点
            Line s1 = new Line(startPoint, wx2.StartPoint);
            Line s2 = new Line(s1.StartPoint.CP(0, -50), s1.EndPoint.CP(0, -50));
            //s3
            Line s3 = new Line(ws1.EndPoint, wx2.EndPoint);
            Line s4 = new Line(s3.StartPoint.CP(0, 50), s3.EndPoint.CP(0, 50));

            //ks1 参照ws1
            Line ks1 = new Line(startPoint.CP(295, -25), startPoint.CP(355, -25));
            //ks2 参照ks2  开孔2
            Line ks2 = new Line(ws1.EndPoint.CP(295, 25), ws1.EndPoint.CP(355, 25));


            //创建钢瓶圈
            double br = 248 / 2.0;
            double sr = 163 / 2.0;

            Circle cw1 = new Circle(startPoint.CP(187.5, -235), Vector3d.ZAxis, br);
            Circle cn1 = new Circle(cw1.Center, Vector3d.ZAxis, sr);
            entities.Add(cw1);
            entities.Add(cn1);

            Circle cw2_1 = null;
            if (sub_num>1)
            { 
                cw2_1 = new Circle(startPoint.CP(462.5, -235), Vector3d.ZAxis, br);
                Circle cn2_1 = new Circle(cw2_1.Center, Vector3d.ZAxis, sr);
                entities.Add(cw2_1);
                entities.Add(cn2_1);
            }

            if (num > 1)
            {
                for (int i = 1; i < num; i++)
                {
                    Circle cw = new Circle(cw1.Center.CP(0, -320 * i), Vector3d.ZAxis, br);
                    Circle cws = new Circle(cw1.Center.CP(0, -320 * i), Vector3d.ZAxis, sr);
                    entities.Add(cw);
                    entities.Add(cws);
                    //if (num1 > 0 && i < num - 1)
                    if (i < num)
                    {
                        if (num1 > 0 && i == num - 1) break;
                        if (sub_num>1)
                        {
                            if (cw2_1 != null)
                            {
                                Circle cw2 = new Circle(cw2_1.Center.CP(0, -320 * i), Vector3d.ZAxis, br);
                                Circle cws2 = new Circle(cw2_1.Center.CP(0, -320 * i), Vector3d.ZAxis, sr);
                                entities.Add(cw2);
                                entities.Add(cws2);
                            }
                        }
                    }
                }
            }

            entities.Add(ws1);
            entities.Add(ns1);
            entities.Add(jlg);
            entities.Add(nx2);
            entities.Add(wx2);
            entities.Add(s1);
            entities.Add(s2);
            entities.Add(s3);
            entities.Add(s4);
            entities.Add(ks1);
            entities.Add(ks2);
            return entities;
        }
    }
}